package com.link510.aitools.framework.activity;

import android.app.Application;
import android.content.Context;

import com.blankj.utilcode.util.Utils;
import com.google.common.collect.Lists;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechUtility;
import com.link510.aitools.core.data.model.DeviceShowModel;
import com.link510.aitools.core.domain.device.DeviceInfo;
import com.link510.aitools.core.domain.product.ProductInfo;
import com.link510.aitools.core.domain.product.ProductProtocolInfo;
import com.link510.aitools.services.ApplicationUtils;
import com.orhanobut.hawk.Hawk;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;

import java.util.List;

import lombok.Getter;


public class BaseApplication extends Application {

    /**
     * 设备信息
     */
    @Getter
    private String deviceSN = "";
    /**
     * 设备信息
     */
    @Getter
    private DeviceInfo deviceInfo = null;

    /**
     * 产品信息
     */
    @Getter
    private ProductInfo productInfo = null;

    /**
     * 产品协议信息
     */
    @Getter
    private List<ProductProtocolInfo> productProtocolInfoList = Lists.newArrayList();


    @Override
    public void onCreate() {
        super.onCreate();
        Utils.init(BaseApplication.this);
        ApplicationUtils.getInstance().init(this);
        initModule(BaseApplication.this);
        initService();
    }

    /**
     * 初始化模块
     *
     * @param context 上下文
     */
    private void initModule(final Context context) {
        Hawk.init(context).build();
        Logger.addLogAdapter(new AndroidLogAdapter());
        SpeechUtility.createUtility(context, SpeechConstant.APPID + "=5ff7fc5e");
    }

    /**
     * 初始化服务
     */
    private void initService() {

    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }


    /**
     * 设备登录
     *
     * @param model 设备信息
     */
    public void login(DeviceShowModel model) {

        synchronized (Application.class) {
            this.deviceSN = model.getDeviceSN();
            this.deviceInfo = model.getDeviceInfo();
            this.productInfo = model.getProductInfo();
            this.productProtocolInfoList = model.getProductProtocolInfoList();
        }

    }

}
